package com.gzhuxj201.mapper;

import com.gzhuxj201.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseMapper {

    List<Course> selectByCnos(List<String> cnos);

    @Insert("insert into course(Cno,Cname,cYear,cTerm) values(#{Cno},#{Cname},#{cYear},#{cTerm})")
    int add(Course course);

    int updateByCno(Course course);

    @Select("select * from course where cno=#{cno}")
    Course selectByCno(String cno);

    @Delete("delete from course where cno=#{cno}")
    int deleteByCno(String cno);

    @Select("select * from course where canSelect=1")
    List<Course> selectByCanSelect();

    @Update("update course set curNum=curNum+1 where cno=#{cno} and curNum<maxNum")
    int updateCurNumByCno(String cno);

    @Update("update course set curNum=curNum-1 where cno=#{cno} and curNum=#{curNum}")
    int updateCurNumByCourse(Course course);
}
